import 'package:cloudapp/esdk/response/album_item_info.dart';
import 'package:cloudapp/pages/picture_list_page.dart';
import 'package:flutter/material.dart';
import 'dart:convert' as convert;

var albumPlaceHolder = Image.asset(
  'res/images/album.png',
  width: 100,
  height: 100,
  fit: BoxFit.none,
);

class AlbumItem extends StatelessWidget {
  final AlbumItemInfo album;
  AlbumItem({Key key, @required this.album}):super(key: key);

  @override
  Widget build(BuildContext context) {
    // 如果有预览图，则加载，否则使用默认占位符
    Widget img;
    if(album.thumb.isNotEmpty) {
      var bytes = convert.base64Decode(album.thumb);
      img = Image.memory(
        bytes,
        width: 100,
        height: 100,
        fit: BoxFit.none,
      );
    } else {
      img = albumPlaceHolder;
    }
    return GestureDetector(
      onTap: () {
        Navigator.pushNamed(context, PictureListPage.pageName, arguments: album.id);
      },
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: <Widget>[
          img,
          Text(
            album.name,
            textAlign: TextAlign.center,
            maxLines: 1,
            overflow: TextOverflow.ellipsis,
            style: TextStyle(
              fontSize: 12.0,
            ),
          )
        ],
      ),
    );
  }
}
